<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * @param $msg string 提示信息
 * @param int $status 状态码 0为失败 1为成功
 * @param array $data 数据
 * @return array
 */
function resposer($msg, $status = 0, $data = [])
{
    $data = [
        'msg' => $msg,
        'status' => $status,
        'data' => $data,
    ];
    return $data;
}

function return_api($status,$message='',$data=[])
{
    $result = [
        'status'=>$status,
        'message'=>$message,
        'data'=>$data,
    ];
    return json_encode($result);
}

/**获取器
 * @param $data数据
 * @param $arr定义的获取器规则
 * @param string $item默认字段
 * @return mixed
 */
function attr($data, $arr, $item = 'status')
{
    foreach ($data as $k => $v) {
        $data[$k][$item] = isset($arr[$v[$item]])?$arr[$v[$item]]:'未知';
    }
    return $data;
}


/**
 * 校验$value是否非空
 *  if not set ,return true;
 *    if is null , return true;
 **/
function checkEmpty($value) {
    if (!isset($value))
        return true;
    if ($value === null)
        return true;
    if (trim($value) === "")
        return true;
    return false;
}

function pr($data){
    echo '<pre>';
    print_r($data);die;
}